import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;

public class C57 {
    public static void main(String[] args) {
        /*
         * Similar to Observable.combineLatest(), but not exactly the same, is the withLatestfrom() 
         * operator. It will map each T emission with the latest values from other Observables and 
         * combine them, but it will only take one emission from each of the other Observables:
         */
        Observable<Long> source1 = Observable.interval(300, TimeUnit.MILLISECONDS);
        Observable<Long> source2 = Observable.interval(1, TimeUnit.SECONDS);
        source2.withLatestFrom(source1, (l1, l2) -> "SOURCE 2: " + l1 + " SOURCE 1: " + l2 )
               .subscribe(System.out::println);
        sleep(3000);
    }

    public static void sleep(long millis) {
        try {
            Thread.sleep(millis);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
//EOP
